package com.guestbook.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class EncodingFilter implements Filter {

	private FilterConfig config;
	private String encoding="ISO8859_1";
	

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		request.setCharacterEncoding(encoding);
		chain.doFilter(request, response);//进行下一个过滤
	}

	public void init(FilterConfig config) throws ServletException {
		this.config=config;
		String s=config.getInitParameter("encoding");//获取在web.xml中的参数
		if(s!=null){
			encoding=s;
		}
	}
	public void destroy() {
		config=null;
	}
}
